package com.example.tests;

import java.io.File;
import java.io.FileReader;
import java.util.Properties;

import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;

import com.example.fw.AppManager;

public class TestBase {
	
	static AppManager app;

	@BeforeSuite
	public void setUp() throws Exception {
        // удалим БД приложения
        File file = new File("datastorage.xml");
        if (file.exists()) {
            try{
                file.delete();
            }catch(Exception e){
                throw new Exception("Failed to prepare test environment" + e.getMessage());
            }
        }

        // загрузим настройки и приложение
		Properties properties = new Properties();
		String configFile = System.getProperty("configFile", "application.properties");
		properties.load(new FileReader(new File(configFile)));
		app  = new AppManager(properties);
	  }

	@AfterSuite
	public void tearDown() throws Exception {
		app.stop();
	  }
}
